/*Kyle Kelly*/

#include <stdlib.h>
#include <stdio.h>

typedef void (*print_func)(int);
typedef int (*do_func)(int);

void printInt(int);
void printEvens(int);
void printOdds(int);
int doubleInt(int);
int squareInt(int);
int absVal(int);
void traverse(int*, size_t, print_func);
void collect(int*, size_t, do_func);

int main(){
	int list[10];
	int len = sizeof(list)/sizeof(int);
	for(int i = 0; i<10;i++)
		list[i] = i;
	printf("Evens: \n");
	traverse(list, len, printEvens);
	printf("\n\n");
	printf("Odds: \n");
	traverse(list,len, printOdds);
	printf("\n\n");
	printf("Doubled: \n");
	collect(list, len, doubleInt);
	traverse(list, len, printInt);
	printf("\n\n");
	printf("Square: \n");
	collect(list, len, squareInt);
	traverse(list, len, printInt);
	printf("\n\n");
	printf("AbsVal: \n");
	collect(list, len, absVal);
	traverse(list, len, printInt);
	printf("\n\n");
}

void printInt(int val){
	printf("%d\t", val);
}

void printEvens(int val){
	if(val%2 ==0)
		printInt(val);
}

void printOdds(int val){
	if(val%2)
		printInt(val);
}

int doubleInt(int val){
	return val*2;
}

int squareInt(int val){
	return val*val;
}

int absVal(int val){
	if(val<0)
		return -val;
	return val;
}

void traverse(int *array, size_t len, print_func func){
	for(int i = 0; i<len; i++)
		(*func)(array[i]);
}

void collect(int *array, size_t len, do_func func){
	for(int i = 0; i<len; i++)
		array[i] = (*func)(array[i]);
}
